package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.DormListEntity;
import com.ruoyi.web.dorm.entity.StudentEntity;
import com.ruoyi.web.dorm.entity.dto.StudentDTO;
import com.ruoyi.web.dorm.entity.vo.DormStudentVo;
import com.ruoyi.web.dorm.entity.vo.StudentVO;
import com.ruoyi.web.dorm.service.DormListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/dormList")
public class DormListController extends BaseController {

    @Autowired
    private DormListService dormListService;

    /**
     * 查询宿舍信息
     * @param dormListEntity
     * @return
     */
    @GetMapping("/getDormList")
    public TableDataInfo getDormList(DormListEntity dormListEntity){
        startPage();
        return getDataTable(dormListService.getDormList(dormListEntity));
    }

    /**
     * 添加宿舍信息
     * @param dormListEntity
     * @return
     */
    @PostMapping("/addDormList")
    public AjaxResult addDormList(@RequestBody DormListEntity dormListEntity ){
        return toAjax(dormListService.addDormList(dormListEntity));
    }

    /**
     * 更新宿舍信息
     * @param dormListEntity
     * @return
     */
    @PostMapping("/updateDormList")
    public AjaxResult updateDormList(@RequestBody DormListEntity dormListEntity){
        return toAjax(dormListService.updateDormList(dormListEntity));
    }

    /**
     * 删除宿舍信息
     * @param id
     * @return
     */
    @DeleteMapping("/delDormList")
    public AjaxResult delDormList(Long id){
        return toAjax(dormListService.delDormList(id));
    }



    /**
     * 查询宿舍信息导出信息
     * @param dormListEntity
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, DormListEntity dormListEntity){
        List<DormListEntity> list = dormListService.getDormList(dormListEntity);
        ExcelUtil<DormListEntity> util = new ExcelUtil<>(DormListEntity.class);
        util.exportExcel(response,list,"宿舍信息数据");
    }



    /**
     * 查询宿舍人员信息
     * @param dormStudentVo
     * @return
     */
    @GetMapping("/getDormStudent")
    public TableDataInfo getDormStudent(DormStudentVo dormStudentVo){
        startPage();
        return getDataTable(dormListService.getDormStudent(dormStudentVo));
    }















}
